<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Articlecat;

class ArcatController extends Controller
{
    //
    public function getadd(){
    	return view('admin/arcatadd');
    }

    public function postadd(request $req){
    		$cats=new Articlecat;
    		$cats->style=$req->style;

    		return $cats->save()?'添加成功':'添加失败';
    }

    //栏目列表
    public function arcatlist(){
    	$cats=Articlecat::paginate(3);
    	return view('admin\arcatlist',['cats'=>$cats]);
    }

    //栏目编辑
    public function arcatedit(request $req,$cid){

    	if(empty($req->all())){
    		$cat=Articlecat::where('cat_id',$cid)->first();
    		return view('admin/arcatedit',['cat'=>$cat]);
    	}else{
    	 
    		$arc=Articlecat::find($cid);
    		$arc->style=$req->style;
    		return $arc->save()?redirect('arcatlist'):'修改失败';
    	}
    }

    //栏目删除
    public function arcatdel($cid){
    	return Articlecat::where('cat_id',$cid)->delete()?redirect('arcatlist'):'删除失败';
    }
}
